package cyan.gf.util;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;

/**
 * Created by cyan on 2017/1/23.
 * Email:qsyan@vip.qq.com
 */
public class StageUtil {

  FXMLLoader loader;
  protected static Logger logger = LogManager.getLogger(StageUtil.class);

  public Stage initStage(String resouces, int w, int h, String title) {
    Parent root = null;
    try {
      loader = new FXMLLoader();
      loader.setLocation(getClass().getResource(resouces));
      root = loader.load();
    } catch (IOException e) {
      logger.error(e);
    }
    Stage stage = new Stage();
    stage.getIcons().add(new Image("/images/logo.png"));
    Scene primaryScene = new Scene(root, w, h);
    stage.setTitle(title);
    stage.setScene(primaryScene);
    return stage;
  }

  public FXMLLoader getLoader() {
    return loader;
  }

}
